package cang.string.Day04.io;

import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

import java.io.*;

public class CopyDemo01 {
    public static void main(String[] args) throws IOException {
        /**
         * 利用IO流复制文件
         * 复制原理：
         * 将源文件打开，一字节一字节读取文件
         * 将目标文件打开，一字节一字节读写入数据
         */
        //in 是原始文件
        FileInputStream in = new FileInputStream("./照片/1920.jpg");
        //out是目标新文件
        FileOutputStream out = new FileOutputStream("./11.jpg");

        /**
         * in = 01100111 10111101 11100111 00110001         ----
         *      0        1        2        3        4  ... 90
         *指针
         * b= in.read();
         * int b =00000000 00000000 00000000 00000000
         * out.write(b)
         * out = 01100111 10111101 -------- -------- --------
         *
         * 指针
         *
         */
        byte[] B = new byte[25];
        long t1 = System.currentTimeMillis();
        int b;
        while ((b=in.read(B))!=-1){
            //不要再次调用read()
            out.write(B);
        }
        in.close();
        out.close();
        long t2 = System.currentTimeMillis();
        System.out.println((t2-t1));
//        File f= new File("./11");
//        f.delete();


    }
}
